import 'package:flutter/widgets.dart';

class AppFooterTranslation {
  static final delegate = _AppFooterTranslationDelegate();

  static AppFooterTranslation of(BuildContext context) {
    return Localizations.of(context, AppFooterTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get legalInformationBlockTitle {
    return _resolve(const {
      'ru': 'Правовая информация',
    });
  }

  String buildPrivacyPolicyLabelMarkdown({
    required String privacyPolicyHref,
  }) {
    return _resolve({
      'ru': '[Политика конфиденциальности]($privacyPolicyHref)',
    });
  }

  String buildTermsOfUseLabelMarkdown({
    required String termsOfUseHref,
  }) {
    return _resolve({
      'ru': '[Условия использования]($termsOfUseHref)',
    });
  }

  String get supportBlockTitle {
    return _resolve(const {
      'ru': 'Поддержка',
    });
  }

  String buildFaqLabelMarkdown({
    required String faqPageHref,
  }) {
    return _resolve({
      'ru': '[Вопросы и ответы]($faqPageHref)',
    });
  }

  String buildSupportEmailLabelMarkdown({
    required String supportEmail,
    required String supportEmailHref,
  }) {
    return _resolve({
      'ru': '[$supportEmail]($supportEmailHref)',
    });
  }

  String buildCopyrightLabel({
    required DateTime currentTime,
  }) {
    return _resolve({
      'ru': '© Angry Words, 2020 – ${currentTime.year}',
    });
  }

  String get aboutCompanyBlockTitle {
    return _resolve(const {
      'ru': 'О компании',
    });
  }

  String get companyNameLabel {
    return _resolve(const {
      'ru': 'ООО Энгри Вордс',
    });
  }

  String buildCompanyInnLabel({
    required String inn,
  }) {
    return _resolve({
      'ru': 'ИНН: $inn',
    });
  }

  String buildCompanyOgrnLabel({
    required String ogrn,
  }) {
    return _resolve({
      'ru': 'ОГРН: $ogrn',
    });
  }

  String get aboutAppBlockTitle {
    return _resolve(const {
      'ru': 'О приложении',
    });
  }

  String buildDocumentationLabelMarkdown({
    required String documentationPageHref,
  }) {
    return _resolve({
      'ru': '[Документация]($documentationPageHref)',
    });
  }
}

class _AppFooterTranslationDelegate extends LocalizationsDelegate<AppFooterTranslation> {
  @override
  bool isSupported(Locale locale) => const ['ru'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<AppFooterTranslation> old) => false;

  @override
  Future<AppFooterTranslation> load(Locale locale) async {
    final translation = AppFooterTranslation();
    await translation.load(locale);
    return translation;
  }
}
